﻿
using System;
using System.Data;
using System.Collections.Generic;

namespace LDSP.BRL
{
    public partial class LoginLog : BYFW.BOL.BaseEntity
    {
        public LoginLog()
        {
            m_tableName = "t_loginLog";
            m_tblCacheManager.IsEnable = true;
        }

        protected int m_enterpriseUserID = 0;
        protected DateTime m_loginDT = DateTime.Now;
        protected DateTime m_logoutDT = DateTime.Now;
        protected string m_loginIP = string.Empty;
        protected EnterpriseUser m_enterpriseUser = null;

        /// <summary>
        /// 企业用户ID
        /// </summary>
        public int EnterpriseUserID
        {
            get { return m_enterpriseUserID; }
            set { m_enterpriseUserID = value; }
        }
        /// <summary>
        /// 登陆时间
        /// </summary>
        public DateTime LoginDT
        {
            get { return m_loginDT; }
            set { m_loginDT = value; }
        }
        /// <summary>
        /// 登陆IP
        /// </summary>
        public string LoginIP
        {
            get { return m_loginIP; }
            set { m_loginIP = value; }
        }
        /// <summary>
        /// 登出时间
        /// </summary>
        public DateTime LogoutDT
        {
            get { return m_logoutDT; }
            set { m_logoutDT = value; }
        }

        public EnterpriseUser EnterpriseUser
        {
            get
            {
                if (m_enterpriseUser == null)
                {
                    m_enterpriseUser = new EnterpriseUser();
                    if (m_enterpriseUserID != 0)
                    {
                        m_enterpriseUser.GetProperties(m_enterpriseUserID);
                    }
                }
                return m_enterpriseUser;
            }
        }

        protected override void FillContainer()
        {
            base.FillContainer();
            m_container.Add("enterpriseUserID", m_enterpriseUserID);
            m_container.Add("loginDT", m_loginDT);
            m_container.Add("loginIP", m_loginIP);
            m_container.Add("logoutDT", m_logoutDT);
        }

        public override bool GetProperties(System.Data.DataRow record)
        {
            if (!base.GetProperties(record))
            {
                return false;
            }
            m_enterpriseUserID = this.GetIntValue(record, "enterpriseUserID");
            m_loginDT = this.GetDateValue(record, "loginDT");
            m_loginIP = this.GetStringValue(record, "loginIP");
            m_logoutDT = this.GetDateValue(record, "logoutDT");
            return true;
        }

        public DataTable GetRecordsByCond(string cond)
        {
            string sql = @"select * from (select t1.*, t2.name as enterpriseUserName, t3.id as enterpriseID, t3.code as enterpriseCode  from t_loginLog t1
                left join t_enterpriseUser t2 on t1.enterpriseUserID = t2.id
                left join t_enterprise t3 on t2.enterpriseID=t3.id) t4";
            sql += cond;
            return DB.Select(sql).Tables[0];
        }

    }
}